function ajaxRequest({ method = 'GET', url, data = null }) {
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        method = method.toUpperCase();

        xhr.open(method, url);

        // 设置JSON请求头
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.setRequestHeader('Accept', 'application/json');
        // 新增认证头
        const token = sessionStorage.getItem('token');
        if (token) {
            xhr.setRequestHeader('Authorization', `Bearer ${token}`);
        }

        xhr.onload = () => {
            if (xhr.status >= 200 && xhr.status < 300) {
                try {
                    const response = JSON.parse(xhr.responseText);
                    resolve(response);
                } catch (e) {
                    reject({ msg: 'JSON解析失败', status: xhr.status });
                }
            } else {
                reject({ msg: xhr.statusText, status: xhr.status });
            }
        };

        xhr.onerror = () => reject({ msg: '网络请求失败' ,status:10000});
        xhr.timeout = 30000; // 30秒超时
        xhr.ontimeout = () => reject({ msg: '请求超时' ,status:10001});

        // 发送格式化数据
        xhr.send(data ? JSON.stringify(data) : null);
    });
}